package vip.xiaonuo.smzq.modular.kcl.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import vip.xiaonuo.smzq.modular.kcl.entity.Bg;
import vip.xiaonuo.smzq.modular.kcl.entity.Ksjj;
import vip.xiaonuo.smzq.modular.kcl.mapper.KsjjMapper;
import vip.xiaonuo.smzq.modular.kcl.service.IKsjjService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import vip.xiaonuo.common.page.CommonPageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * 矿山经济 服务实现类
 *
 * @author eomer
 * @since 2024-02-22
 */
@Service
public class KsjjServiceImpl extends ServiceImpl<KsjjMapper, Ksjj> implements IKsjjService {

    @Resource
    private KsjjMapper ksjjMapper;

    @Override
    public Page<Ksjj> page(Ksjj ksjj) {
        QueryWrapper<Ksjj> queryWrapper = new QueryWrapper<>();
        return this.page(CommonPageRequest.defaultPage(), queryWrapper);
    }

    /**
     * 矿山经济查询详情
     *
     * @Param kqbm 矿区编码
     * @Param djflbm 登记分类编码
     * @Param nd 年度
     */
    @Override
    public Ksjj getKsjjDetails(String kqbm, Integer djflbm, Integer nd) {
        Ksjj ksjj = new Ksjj();
        try {
            QueryWrapper<Ksjj> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("kqbh", kqbm);
            queryWrapper.eq("djflbh", djflbm);
            queryWrapper.eq("nd", nd);
            ksjj=ksjjMapper.selectOne(queryWrapper);
        }catch (Exception e){
            e.printStackTrace();
        }

        return ksjj;
    }

    /**
     * 矿山经济添加详情
     *
     * @param ksjj
     * @return
     */
    @Override
    public int addKsjj(Ksjj ksjj,String kqbm, Integer djflbm, Integer nd) {
        ksjj.setDjflbh(djflbm);
        ksjj.setKqbh(kqbm);
        ksjj.setNd(nd);

        int count = 0;
        //通过查询是否是新数据，是则添加，不是则更新
        if (ksjj.getPkid() != null) {
            count = ksjjMapper.updateById(ksjj);
        } else {
            count = ksjjMapper.insert(ksjj);
        }
        return count;
    }

    @Override
    public List<Ksjj> selectList(QueryWrapper<Ksjj> queryWrapperKsjj) {
        return ksjjMapper.selectList(queryWrapperKsjj);
    }
}
